/*
*********************************************************************************************************
*                                   Embedded Systems Building Blocks
*                                Complete and Ready-to-Use Modules in C
*
*                                         Matrix Keyboard Driver
*
*                            (c) Copyright 1999, Jean J. Labrosse, Weston, FL
*                                           All Rights Reserved
*
* Filename   : KEY.H
* Programmer : Jean J. Labrosse
*********************************************************************************************************
*                                          USER DEFINED CONSTANTS
*
* Note: These #defines would normally reside in your application specific code.
*********************************************************************************************************
*/

#ifndef  CFG_H
#define  KEY_BUF_SIZE               10      /* Size of the KEYBOARD buffer                             */

//#define  KEY_PORT_ROW           0x0312      /* The port address of the keyboard matrix ROWs            */
//#define  KEY_PORT_COL           0x0311      /* The port address of the keyboard matrix COLUMNs         */
//#define  KEY_PORT_CW            0x0313      /* The port address of the I/O ports control word          */
sbit	KEY_PORT_ROWA =				P3^2;
sbit	KEY_PORT_ROWB =				P3^3;
sbit	KEY_PORT_ROWC =				P3^4;
sbit	KEY_PORT_ROWD =				P3^5;
									
sbit	KEY_PORT_COL1 =				P2^5;
sbit	KEY_PORT_COL2 =				P2^6;
sbit	KEY_PORT_COL3 =				P2^7;

#define  KEY_MAX_ROWS                4      /* The maximum number of rows    on the keyboard           */
#define  KEY_MAX_COLS                3      /* The maximum number of columns on the keyboard           */

#define  KEY_RPT_DLY                10      /* Number of scan times before auto repeat executes again  */
#define  KEY_RPT_START_DLY          20      /* Number of scan times before auto repeat function engages*/

#define  KEY_SCAN_TASK_DLY          50      /* Number of milliseconds between keyboard scans           */
#define  KEY_SCAN_TASK_PRIO         9      /* Set priority of keyboard scan task                      */
#define  KEY_SCAN_TASK_STK_SIZE    100      /* Size of keyboard scan task stack                        */

#define  KEY_SHIFT1_MSK           0x00      /* The SHIFT1 key is on bit B7 of the column input port    */
                                            /*     (A 0x00 indicates that a SHIFT1 key is not present) */
#define  KEY_SHIFT1_OFFSET          24      /* The scan code offset to add when SHIFT1 is pressed      */

#define  KEY_SHIFT2_MSK           0x00      /* The SHIFT2 key is on bit B6 of the column input port    */
                                            /*     (A 0x00 indicates that an SHIFT2 key is not present)*/
#define  KEY_SHIFT2_OFFSET          48      /* The scan code offset to add when SHIFT2 is pressed      */

#define  KEY_SHIFT3_MSK           0x00      /* The SHIFT3 key is on bit B5 of the column input port    */
                                            /*     (A 0x00 indicates that a SHIFT3 key is not present) */
#define  KEY_SHIFT3_OFFSET           0      /* The scan code offset to add when SHIFT3 is pressed      */
#endif


#define  KEY_ALL_ROWS             0xFF      /* Select all rows (i.e. all rows LOW)                     */
#define  KEY_ALL_COLS			  0xFF
/*
*********************************************************************************************************
*                                           FUNCTION PROTOTYPES
*********************************************************************************************************
*/

void    KeyFlush(void) reentrant;                /* Flush the keyboard buffer                                    */
INT8U   KeyGetKey(INT16U to) reentrant;          /* Get a key scan code from driver if one is present, -1 else   */
INT32U  KeyGetKeyDownTime(void) reentrant;       /* Get how long key has been pressed (in milliseconds)          */
BOOLEAN KeyHit(void) reentrant;                  /* See if a key has been pressed (TRUE if so, FALSE if not)     */
void    KeyInit(void) reentrant;                 /* Initialize the keyboard handler                              */


void    KeyInitPort(void) reentrant;             /* Initialize I/O ports                                         */
INT8U   KeyGetCol(void) reentrant;               /* Read COLUMNs                                                 */
INT8U   KeyGetRow(void) reentrant;
void    KeySelRow(void) reentrant;          /* Select a ROW                                                 */
void  	KeySelCol (void) reentrant;

